package com.gome.gop.controller.order;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gome.gop.common.RestData;
import com.gome.gop.data.entity.source.AnalyseLineDo;
import com.gome.gop.data.entity.source.PageAnalyseLineRet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.gome.gop.common.Page;
import com.gome.gop.data.entity.source.AddSourceParam;
import com.gome.gop.data.entity.source.AnalyseDo;
import com.gome.gop.data.entity.source.PageAnalyseParam;
import com.gome.gop.service.SourceService;

import java.util.List;

/**
 * @Title:
 * @Description:
 * @Author:chengcheng7
 * @Since: 2022/9/28 10:38
 * @Copyright:Copyright (c) 2018 - 2100
 * @Company:gome
 * @Version:1.1.0
 */

@RestController
@RequestMapping("/source")
public class SourceController {
    
    @Autowired
    private SourceService sourceService;
    
    @RequestMapping(value = "/addAnalyse.json")
    @ResponseBody
    public PageAnalyseLineRet addAnalyse(@RequestBody AddSourceParam addSourceParam) {
        return sourceService.addAnalyse(addSourceParam);
    }
    
    @RequestMapping(value = "/findAnalyse.json")
    @ResponseBody
    public AnalyseDo findAnalyse(@RequestBody AddSourceParam addSourceParam) {
        AnalyseDo analyseDo = new AnalyseDo();
        analyseDo.setId(addSourceParam.getOldId());
        return sourceService.findAnalyse(analyseDo);
    }
    
    @RequestMapping(value = "/pageAnalyseLine.json")
    @ResponseBody
    public PageAnalyseLineRet pageAnalyseLine(@RequestBody AddSourceParam addSourceParam) {
        return sourceService.pageAnalyseLine(addSourceParam);
    }
    
    @RequestMapping(value = "/saveAnalyse.json")
    @ResponseBody
    public PageAnalyseLineRet saveAnalyse(@RequestBody AddSourceParam addSourceParam) {
        return sourceService.saveAnalyse(addSourceParam);
    }
    
    @RequestMapping(value = "/deleteAnalyseLineDoList.json")
    @ResponseBody
    public void deleteAnalyseLineDoList(@RequestBody List<AnalyseLineDo> analyseLineDoList) {
        sourceService.deleteAnalyseLineDoList(analyseLineDoList);
    }
    
    @GetMapping(value = "/pageAnalyse.json")
    @ResponseBody
    public Page pageAnalyse(PageAnalyseParam param) {
        return sourceService.pageAnalyse(param);
    }
    
    @RequestMapping(value = "/exportAnalyse")
    public void exportAnalyse(HttpServletRequest request, HttpServletResponse response) {
        
        PageAnalyseParam param = JSON.parseObject(request.getParameter("pageBean"), PageAnalyseParam.class);
        sourceService.exportAnalyse(param, request, response);
    }
    
    @RequestMapping(value = "/exportAnalyseOne")
    public void exportAnalyseOne(@RequestBody AddSourceParam addSourceParam, HttpServletRequest request, HttpServletResponse response) {
        
        sourceService.exportAnalyseOne(addSourceParam, request, response);
        
    }
    
    @RequestMapping(value = "/deleteAnalyse")
    @ResponseBody
    public RestData deleteAnalyse(@RequestBody AnalyseDo analyseDo) {
        
        sourceService.deleteAnalyse(analyseDo);
        return RestData.makeSuccess();
    }
    
}
